#!/bin/sh

if ! which gnuplot > /dev/null 2>&1
then
    echo 'gnuplot not found - skipping graph creation' >&2
    exit 1
fi

gnuplot<<EOF
    set terminal postscript eps monochrome
    set output '../probabilityDensity.eps'
    set decimalsign '.'

    set format x '%g'
    set format y '%.1f'
    set xtics 1 mirror
    set xlabel 'd(m)'
    set ytics 0.1 mirror
    set ylabel 'Probability density function (m^{-3})'

    set xrange [1:10]
    set yrange [0:0.4]
    set key below

    plot '-' w l t 'Number density, [Vanni, J. Colloid Interface Sci., 221: 143-160, 2000]',\
    '-' w l t 'Volume density, [Vanni, J. Colloid Interface Sci., 221: 143-160, 2000]',\
    '../numberDensity.transposed.dat' every ::0::12 u 1:2 w p pt 1 t 'Number density, air1',\
    '../numberDensity.transposed.dat' every ::13::22 u 1:2 w p pt 5 t 'Number density, air2',\
    '../numberDensity.transposed.dat' every ::23::30 u 1:2 w p pt 9 t 'Number density, air3',\
    '../volumeDensity.transposed.dat' every ::0::12 u 1:2 w p pt 2 t 'Volume density, air1',\
    '../volumeDensity.transposed.dat' every ::13::22 u 1:2 w p pt 6 t 'Volume density, air2',\
    '../volumeDensity.transposed.dat' every ::23::30 u 1:2 w p pt 10 t 'Volume density, air3'
    1.000   0.042
    1.460   0.062
    1.950   0.083
    2.403   0.100
    2.775   0.116
    3.109   0.127
    3.562   0.141
    4.015   0.151
    4.475   0.162
    4.876   0.172
    5.270   0.179
    5.700   0.188
    6.035   0.190
    6.436   0.188
    6.777   0.178
    7.163   0.157
    7.416   0.137
    7.705   0.109
    7.980   0.078
    8.285   0.047
    8.589   0.026
    8.953   0.010
    9.228   0.003
    9.495   0.002
    EOF
    0.993   0.000
    0.985   0.002
    1.475   0.003
    1.965   0.005
    2.485   0.010
    2.975   0.020
    3.488   0.032
    3.985   0.055
    4.468   0.084
    4.995   0.123
    5.507   0.176
    6.087   0.240
    6.532   0.289
    6.755   0.309
    7.007   0.326
    7.260   0.324
    7.535   0.305
    7.683   0.284
    7.839   0.252
    8.017   0.215
    8.196   0.172
    8.351   0.137
    8.574   0.090
    8.723   0.065
    8.946   0.037
    9.161   0.021
    9.339   0.013
    9.517   0.006
    9.770   0.004
    9.993   0.002
    EOF
EOF

#------------------------------------------------------------------------------
